wasm: lazily initialize tls.std, add configuration macro for assert logging#7
Merged
Merged
Conversation
…ogging sp_assert_f unconditionally logged a nice message when triggered. This, however, forced WASM builds to pull in fd_write. In the browser, this forces you to shim fd_write with no recourse, even if you don't want the logging. Added a macro to configure what happens on assert (nothing, trap only, trap and log). I decided against a higher level configuration (like SP_NO_IO); it's a little unintuitive that, if you were to pull in sp.h for such a WASM thing, that it defaults to wanting fd_write and the configuration to turn that off is hidden in the configuration for assert. Fairly unintuitive. But sp_assert_f() is legitimately the only place that the library writes output. It's a standard library. It SHOULDN'T log during normal use. Presenting a macro framed as "make this library log" is equally confusing. I also considered defaulting to trap only on WASM, but that degrades the equally common case of running a WASM program inside a preview1 enabled environment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sp_assert_f unconditionally logged a nice message when triggered. This, however, forced WASM builds to pull in fd_write. In the browser, this forces you to shim fd_write with no recourse, even if you don't want the logging.
Added a macro to configure what happens on assert (nothing, trap only, trap and log). I decided against a higher level configuration (like SP_NO_IO); it's a little unintuitive that, if you were to pull in sp.h for such a WASM thing, that it defaults to wanting fd_write and the configuration to turn that off is hidden in the configuration for assert. Fairly unintuitive.
But sp_assert_f() is legitimately the only place that the library writes output. It's a standard library. It SHOULDN'T log during normal use. Presenting a macro framed as "make this library log" is equally confusing. I also considered defaulting to trap only on WASM, but that degrades the equally common case of running a WASM program inside a preview1 enabled environment.